package com.ryan.mdp.connection;

import javax.jms.ConnectionFactory;
import javax.jms.XAConnectionFactory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import com.atomikos.jms.AtomikosConnectionFactoryBean;

/**
 * atomikos支持的JTA连接工厂，适应于tomcat等不提供JTA支持的容器
 * 
 * @author botao.liao
 * 
 */
public class MdpXaConnectionFactory extends AtomikosConnectionFactoryBean implements InitializingBean, DisposableBean {

    private static final long serialVersionUID = 1L;

    // jms连接配置信息文件路径
    private String properties;
    // jms连接配置信息中的key前缀
    private String prefix;

    // 是否需要分布式事务

    public void afterPropertiesSet() {
        ConnectionFactory connectionFactory = JndiConnectionFactoryUtil.getConnectionFactory(prefix, properties);
        setXaConnectionFactory((XAConnectionFactory) connectionFactory);
    }

    public void destroy() {
        close();
    }

    public String getProperties() {
        return properties;
    }

    public void setProperties(String properties) {
        this.properties = properties;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }
}
